{% extends 'base.html' %}
{% block head %}
	<link href="{{ path }}js/plugins/datatables/DT_bootstrap.css" rel="stylesheet">
	<link href="{{ path }}js/plugins/responsive-tables/responsive-tables.css" rel="stylesheet"> 
    
    <script src="{{ path }}js/demos/demo.tables.js"></script>
    <script src="{{ path }}js/plugins/datatables/jquery.dataTables.js"></script>
    <script src="{{ path }}js/plugins/datatables/DT_bootstrap.js"></script>
	<script src="{{ path }}js/plugins/responsive-tables/responsive-tables.js"></script>
    <script src="{{ path }}js/jquery.numeric.js"></script>
    
{% endblock %}
	
{% block jquery %}	
	
    $("#btn-nuevo").click(function() {
        registrarProveedor(0);
    });
    
{% endblock %}

{% block javascript %}
	function registrarProveedor(proveedor_id){
        $.ajax({
            url: "/inventario/proveedores/nuevo/",
            type: "POST",
            data : {proveedor_id:proveedor_id,
                    csrfmiddlewaretoken : $('#csrf_token >div >input').attr("value")
                     },
            dataType: "html",
            success: function(datos) {
                $('#nuevo-proveedor').html(datos);
            }
        });
    }
	
    function eliminar(proveedor_id){
            $.ajax({
              url: "/inventario/proveedores/borrar/",
              type: "POST",
              data : {proveedor_id:proveedor_id, 
                       },
              dataType: "html",
              success: function(datos) {
                    if(datos==1){
                        location.reload(true);
                    }
                    else{
                        alert("El proveedor tiene registros asociados y no puede ser eliminado.");
                    }
                  
              }
          });
        return false;
    }

{% endblock %}

{% block contenido %}
	{{ request.session.control }}
    	
    	<div class="span12">
            <div class="widget">	
                <div class="widget widget-table">   
                    <div class="widget-header">						
                        <h3>
                            <i class="icon-th-list"></i>
                            Proveedores
                        </h3>
                    </div> <!-- /widget-header -->
                    <form id="frm_borrar" action="/inventario/proveedores/borrar/" method="post">
                    <div class="widget-content">
                        {% csrf_token %}
                        <table class="table table-striped table-bordered table-highlight" id="example">
                            <thead>
                            <tr>
                                <th width="7%" align="center">Nit</th>
                                <th width="15%" align="center">Nombre</th>
                                <th width="15%" align="center">Direccion</th>
                                <th width="10%" align="center">Telefono</th>
                                <th width="10%" align="center">Fax</th>
                                <th width="10%" align="center">Email</th>
                                <th width="10%" align="center">Web</th>
                                <th width="5%" align="center">Laboratorio</th>
                                <th width="10%" align="center">Observaciones</th>
                                <th width="4%" align="center">Editar</th>
                                <th width="4%" align="center">Borrar</th>
                            </tr>
                            </thead>
                            <tbody>
                            {% for proveedor in Proveedores %}
                                <tr class="{% cycle '' 'odd' %}">
                                    <td align="right"><label>{{ proveedor.nit }}</label></td>
                                    <td align="left"><label>{{ proveedor.nombre }}</label></td>
                                    <td align="left"><label>{{ proveedor.direccion|default_if_none:"" }}</label></td>
                                    <td align="center"><label>{{ proveedor.telefono|default_if_none:"" }}</label></td>
                                    <td align="center"><label>{{ proveedor.fax|default_if_none:"" }}</label></td>
                                    <td align="left"><label>{{ proveedor.email|default_if_none:"" }}</label></td>
                                    <td align="left"><label>{{ proveedor.web|default_if_none:"" }}</label></td>
                                    <td class="table_center" ><label>{% if proveedor.laboratorio %}<img src="{{ path }}img/validate/valid.png"/>
                                                            {% else %}<img src="{{ path }}img/validate/error.png" />{% endif %}</label></td>
                                    <td align="left"><label>{{ proveedor.observaciones|default_if_none:"" }}</label></td>
                                    <td class="table_center" ><a href="#myModal" id="prov_{{ proveedor.id }}" value="{{ proveedor.id }}" data-toggle="modal" ><img src="{{ path }}images/24x24/edit.png" onclick="registrarProveedor({{ proveedor.id }});"/></a></td>
                                    <td><a href="#"><img src="{{ path }}images/delete.png" width="16" height="16" alt="Eliminar" onclick="if(confirm('¿Desea eliminar el proveedor?')){eliminar({{ proveedor.id }});}"/></a></td>
									
                                </tr>
                            {% endfor %}
                            </tbody>
                        </table>
                    </div> <!-- /. widget-content -->
                    <div class="modal-footer">
                        <a id="btn-nuevo" href="#myModal" data-toggle="modal" class="btn btn-primary btn-medium">Nuevo</a>
                    </div>
                    </form>
                </div> <!-- /. widget-table -->
            </div> <!-- /. widget -->
        </div> <!-- /. span12 -->
        <div class="modal fade hide" id="myModal">
	        <form id="form-proveedores" class="form-horizontal" action="/inventario/proveedores/guardar/" method="post" enctype="multipart/form-data">
            <!--<form id="form-proveedores" class="form-horizontal">-->
                  {% csrf_token %}
                  <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal">&times;</button>
                        <h3>Nuevo proveedor</h3>
                  </div>
                  <div class="modal-body" id="nuevo-proveedor">
                        
                       
                  </div>
                  <div class="modal-footer">
                    <!--<a href="#" id="btn_guardar" data-dismiss="modal" class="btn btn-primary">Guardar proveedor</a>-->
                    <a href="#" class="btn btn-medium" data-dismiss="modal">Cerrar</a>
                    <button type="submit" id="btn_guardar" class="btn btn-primary btn-medium">Guardar proveedor</button>
                    
                  </div>
            </form>
        </div>
{% endblock %}